{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_agemoea:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ".. meta::\n",
    "   :description: An implementation of AGE-MOEA algorithm to solve many-objective optimization problems without using on reference directions. The algorithm estimates the shape of the Pareto front to provide a better way to compute proximity to ideal point and crowding distance."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ".. meta::\n",
    "   :keywords: AGEMOEA, NSGA-II, Non-Dominated Sorting, Multi-objective Optimization, Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# AGE-MOEA: Adaptive Geometry Estimation based MOEA"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "AGE-MOEA <cite data-cite=\"agemoea\"></cite> follows the general\n",
    "outline of [NSGA-II](../moo/nsga2.ipynb) but with a modified crowding distance formula. The non-dominated fronts are sorted using the non-dominated sorting procedure. Then the first front is used for normalization of the objective space and estimation of Pareto front geometry. The `p` parameter of a Minkowski p-norm is estimated using the closest solution from the middle of the first front. The p-norm is then used to compute a survival score that combines distance from the neighbors and proximity to the ideal point."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "AGE-MOEA uses a binary tournament mating selection to increase some selection pressure. Each individual is first compared using the rank and then the computed score that represent both proximity and spread."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from pymoo.algorithms.moo.age import AGEMOEA\n",
    "from pymoo.problems import get_problem\n",
    "from pymoo.optimize import minimize\n",
    "from pymoo.visualization.scatter import Scatter\n",
    "\n",
    "problem = get_problem(\"zdt1\")\n",
    "\n",
    "algorithm = AGEMOEA(pop_size=100)\n",
    "\n",
    "\n",
    "res = minimize(problem,\n",
    "               algorithm,\n",
    "               ('n_gen', 200),\n",
    "               seed=1,\n",
    "               verbose=False)\n",
    "\n",
    "plot = Scatter()\n",
    "plot.add(problem.pareto_front(), plot_type=\"line\", color=\"black\", alpha=0.7)\n",
    "plot.add(res.F, facecolor=\"none\", edgecolor=\"red\")\n",
    "plot.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Moreover, we can customize AGE-MOEA to solve a problem with binary decision variables, for example, ZDT5."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from pymoo.algorithms.moo.age import AGEMOEA\n",
    "from pymoo.problems import get_problem\n",
    "from pymoo.operators.crossover.pntx import TwoPointCrossover\n",
    "from pymoo.operators.mutation.bitflip import BitflipMutation\n",
    "from pymoo.operators.sampling.rnd import BinaryRandomSampling\n",
    "from pymoo.optimize import minimize\n",
    "from pymoo.visualization.scatter import Scatter\n",
    "\n",
    "problem = get_problem(\"zdt5\")\n",
    "\n",
    "algorithm = AGEMOEA(pop_size=100,\n",
    "                    sampling=BinaryRandomSampling(),\n",
    "                    crossover=TwoPointCrossover(),\n",
    "                    mutation=BitflipMutation(),\n",
    "                    eliminate_duplicates=True)\n",
    "\n",
    "res = minimize(problem,\n",
    "               algorithm,\n",
    "               ('n_gen', 500),\n",
    "               seed=1,\n",
    "               verbose=False)\n",
    "\n",
    "Scatter().add(res.F, facecolor=\"none\", edgecolor=\"red\").show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This algorithm is based on <cite data-cite=\"agemoea\"></cite> and its Matlab implementation of the PlatEMO library. This Python version has been implemented by [BenCrulis](https://github.com/BenCrulis)  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### API"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. autoclass:: pymoo.algorithms.moo.age.AGEMOEA\n",
    "    :noindex:"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
